﻿<?php

/**
 * Created by PhpStorm. User: ADun, Date: 14-10-15 下午10:11
 * Description:
 */
global $paramArray;

$state = $_GET['state'];
//某些页面要传多个参数时，需要通过state参数分解
if(substr($state,0,3)=='000'){
    $enc=substr($state,3);
    $paramArray=Tools::object2array(json_decode(urldecode($enc)));
}

$课程id = (isset($_GET['id']))? $_GET['id'] : $paramArray['id'];
$openId=getCurrentUserOID();

if(empty($openId)) exit('参数错误');

$bm = new CUI数据中心(Page::m卖家中心_账目,$openId);

$视频列表 = $bm->生成有效链接('Seller17Shipin_LessonsS',$_GET['state']);
$语音课程详情 = $bm->生成有效链接('Seller17Shipin_Lessons',$_GET['state']);
$yuyin=$语音课程详情."&id=".$课程id;
$查看历史信息 = $bm->生成有效链接('Seller17Shipin_LiShiJiLu',$_GET['state']);
$语音课程 = $bm->fc查语音课程($课程id);
$语音课程报名人数 =pdo()->selectOne("SELECT COUNT('id') FROM `语音课程报名` WHERE `课程id` ='".$课程id."' and `状态`='报名';");
$当前用户已报名 = $bm->get当前用户是否报名该课程($课程id);
$课程视频 = $bm->生成有效链接("websocket_shipin",$_GET['state'])."&tid=".$课程id;
if(!$当前用户已报名) $当前用户已报名 =array('id'=>0,'状态'=>'取消报名');
if($当前用户已报名['状态']==='报名') $状态 = '取消报名';
else $状态 = '报名';
$注册 = $bm->生成有效链接('register',$_GET['state']);
$sql = "SELECT   `密码`  from `用户`  where id = ".$_SESSION['vo用户数据']['id'];
$个人信息 = pdo()->selectOne($sql);

$时间冲突 = $bm->检测该用户重复报名($语音课程,$课程id);

require_once __DIR__ . '/jssdk.php';
$数据 = pdo()->selectColumns('public_serv_accounts',array('AppSecret','app_id'),array('id' => G_SERV_ID));
$jssdk = new JSSDK($数据['app_id'], $数据['AppSecret']);
$signPackage = $jssdk->getSignPackage();

$doUser = new Do用户();
$doUser->set_openID($_SESSION['vo用户数据']['openID']);
$doUser->set_unsubscribe(0);

if (!$doUser->where($doUser->data)->row()) {
    $user_status = 1; #未关注
} elseif ($doUser->get_认证() == 1) {
    $user_status = 2; #已关注 未认证
} else {
    $user_status = 3; #已关注 已认证
}

$renzheng_url = $bm->生成有效链接('Seller18ZiLiao',$_GET['state']);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"/>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?= $语音课程['title']?></title>
    <link rel="stylesheet" href="../style/common.css?<?=版本?>">
    <script src="../js/jquery.js"></script>
    <script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="../../app/js/common.js"></script>
    <style>
        .author p{font-size: 11pt; font-family: 华文楷体;}
        .author p span{font-size: 11pt; font-family: 华文楷体;color:#666!important;line-height:1.5;}
    </style>
</head>

<body>
<div class="header">
    <?php
        $认证 = $bm->生成有效链接('Seller18ZiLiao',$_GET['state']);
        $加入聊天 = $bm->生成有效链接('websocket',$_GET['state']);

        #if($_SESSION['vo用户数据']['认证'] === '1' ||!$_SESSION['vo用户数据']['认证'] || $_SESSION['vo用户数据']['认证'] ==''||$_SESSION['vo用户数据']['认证'] ===''){
        #    echo '<a href="'.$认证.'" class="RzFalse"><span>立即认证 >></span></a>';
        #}
    ?>
    <a href="<?= $视频列表?>"   class="list">课程列表</a></div></div>
<div class="class_view">
    <div class="about">
        <div class="box"><div>授课时间</div><h2><?php echo (substr($语音课程['开始时间'],5,2))."月".( substr($语音课程['开始时间'],8,2))."日".( substr($语音课程['开始时间'],11,5)); ?></h2></div>
        <h1><?= $语音课程['title']?></h1>


<!--        <a href="--><?//= $查看历史信息."&sid=".$_GET['id'];?><!--">查看历史消息</a>-->
    </div>


    <style>
        .ab_process{ width:100%; overflow:hidden; margin-top:10px; margin-bottom:10px; padding-bottom:10px; border-bottom:1px solid #C8C8C8; }
        .ab_process .ab_process_btn{ padding:0 20px; margin-bottom:20px; }
        .ab_process .ab_process_btn button{ width:100%; height:40px; border:1px solid #20BE35; border-radius:2px; font-size:100%; color:#FFF; background-color:#20BE35; display:block; }
        .ab_process ul{ overflow:hidden; margin:0 20%; padding:0; background:url(../images/ab_process_ul_bg.png) repeat-x center top; background-size:200px 18px; }
        .ab_process li{ width:33.3%; overflow:hidden; float:left; list-style:none; text-align:center; }
        .ab_process li div{ width:24px; height:24px; border:3px solid #F8F8F8; background-color:#C8C8C8; line-height:24px; text-align:center; font-size:100%; margin:auto; border-radius:24px; color:#FFF; }
        .ab_process li p{ width:100%; text-align:center; font-size:80%; color:#999; font-weight:bold; margin-top:5px; }
        .ab_process .cli div{ border:3px solid #F8F8F8; background-color:#20BE35; }
        .ab_process .cli p{ color:#20BE35; }
        .ab_process .ab_tips{ width:100%; text-align:center; margin-top:10px; }
        .ab_process .ab_tips a{ color:#5C94C6; font-size:80%; }
        /*弹窗*/
        .ab_open{ width:100%; height:100%; display: none; }
        .ab_open_box{ width:100%; height:100%; background:url(../images/black_70.png); position:absolute; left:0; top:0; }
        .ab_open_in{ width:172px; margin-left:-86px; overflow:hidden; text-align:center; position:absolute; left:50%; top:20%; background-color:#FFF; }
        .ab_open_in img{ width:172px; }
        .ab_open_in p{ width:100%; font-size:80%; margin-top:0; text-align:center; color:#999; }
    </style>
    <!--未关注-->
    <?php if ($user_status == 1):?>
    <div class="ab_process">
        <div class="ab_process_btn"><button type="button" onclick="$('.ab_open').show()" >关注爱贝儿医</button></div>
        <ul>
            <li class="cli"><div>1</div><p>关注爱贝</p></li>
            <li><div>2</div><p>医师认证</p></li>
            <li><div>3</div><p>开始上课</p></li>
        </ul>
    </div>
    <?php elseif ($user_status == 2):?>
    <!--已关注未认证-->
    <div class="ab_process">
        <div class="ab_process_btn"><button type="button" onclick="location.href = '<?=$renzheng_url?>'">认证您的医师身份</button></div>
        <ul>
            <li class="cli"><div>1</div><p>关注爱贝</p></li>
            <li class="cli"><div>2</div><p>医师认证</p></li>
            <li><div>3</div><p>开始上课</p></li>
        </ul>
        <div class="ab_tips"><a href="http://mp.weixin.qq.com/s?__biz=MzI3NjE2OTU3NA==&mid=504503549&idx=1&sn=0f7a557e1a4f50d741697ca736ecac11&scene=1&srcid=0614SbnEaam1CfFTrJcDKYcO#wechat_redirect">查看认证流程</a></div>
    </div>
    <?php endif;?>

    <!--弹窗-->
    <div class="ab_open">
        <div class="ab_open_box" onclick="$('.ab_open').hide()"></div>
        <div class="ab_open_in"><img src="../images/erweima.jpg" /><p>长按识别二维码关注爱贝儿医</p></div>
    </div>


    <div class="avatar"><img src="<?php if($语音课程['头像']) echo $语音课程['头像']; else echo "./img/default_avatar.jpg"; ?>" /><p style="font-size: 14pt; font-family: 华文楷体; font-weight: bold;color:#333;"><?=  $语音课程['name']?></p></div>
    <div class="author" style=""><?= htmlspecialchars_decode(stripslashes($语音课程['详情'])) ?>
       <br><br>
        <div style="height:30px;width:100%;color:#db3655;font-size:80%;line-height:30px;text-align:center;">操作过程中如有疑问，请致电客服热线：400-825-8989</div>
    <br><br><br>
 </div>
</div>
<div class="class_view_btn_start">
    <?php
    #更新浏览数
    article_statistic(2, $_SESSION['vo用户数据']['id'], $_GET['id']);

    $时间冲突 = $bm->检测该用户重复报名($语音课程,$课程id);
    if($语音课程['结束时间']< '2016-04-15 00:00:00') {
        $课程 = $语音课程['视频url'];
    } else {
        $课程 = $课程视频.'&视频链接='.$语音课程['视频url'].'&群id='.$语音课程['群id'];
    }

    #已关注已认证才能报名
    if ($user_status == 3) {

        if ($_SESSION['vo用户数据']['id'] == $语音课程['讲课专家id']) {
            ?>
            <a href="<?= $课程 ?>" style="text-decoration: none;"><input type="button" value="进入课程"
                                                                       style="background:#5E94C6;"></a>
        <?php
        } else {

            if ($当前用户已报名 && $语音课程['状态'] === '预备') {
                if ($状态 === '报名') {
                    if ($语音课程报名人数["COUNT('id')"] > $语音课程['课堂人数上限']) {
                        ?>
                        <input type="button" onclick="f人数()" value="报名已满" style="background:red;">
                    <?php } ?>
                    <input type="button" onclick="f报名('<?= $状态 ?>',<?= $当前用户已报名['id'] ?>)" value="报名上课"
                           style="background:#20BE35;">
                <?php } else { ?>
                    <input type="button" value="取消报名" style="background:#B5B5B5;"
                           onclick="f报名('<?= $状态 ?>',<?= $当前用户已报名['id'] ?>)">
                <?php } ?>

            <?php

            } else if ($语音课程['状态'] === '开始') {
                if ($当前用户已报名['状态'] == '报名') {
                    ?>
                    <a href="<?= $课程 ?>" style="text-decoration: none;"><input type="button" value="进入课程"
                                                                               style="background:#5E94C6;"></a>
                <?php } else {
                    if ($语音课程报名人数["COUNT('id')"] > $语音课程['课堂人数上限']) { ?>
                        <input type="button" onclick="f人数()" value="报名已满" style="background:red;">
                    <?php } ?>
                    <input type="button" onclick="f报名('<?= $状态 ?>',<?= $当前用户已报名['id'] ?>)" value="报名上课"
                           style="background:#20BE35;">
                    <!--                <input onclick="f直播()" type="button"  value="正在直播" style="background:#5E94C6;">-->
                <?php
                }
            } else if ($当前用户已报名 && $语音课程['状态'] === '结束') {
                ?><a href="<?= $课程 ?>" style="text-decoration: none;"><input type="button" value="课程回顾"
                                                                             style="background:#5E94C6;"></a>
            <?php
            }
        }
    }
    ?>
</div>
<div class="class_view_btn_closed"></div>
</body>
</html>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script src="../resource/js/hermes.js"></script>

<script>
    function f报名(状态,id){

        var 已报名 ='<?= $时间冲突 ?>';
        var 课程状态 = '<?=$语音课程['状态']?>';

        if(已报名 ==0){

            $.post('agent_manages.php',{'报名id':id,"状态":状态,'课程人数限制':<?php if ($语音课程['课堂人数上限']) echo $语音课程['课堂人数上限']; else echo 500; ?>,'课程id':<?=$课程id?>,'参数':'修改报名语音课程'},function(data) {
                if (data){
                    if (data == '2') {
                        window.location.href="<?=$yuyin?>";
                        return false;
                    } else if(data == 0 || data == '0') {
                        alert(状态 + "失败");
                        window.location.href="<?=$yuyin?>";
                        return false;
                    }

                    if (状态=='取消报名') {
                        alert("取消报名成功!");
                    } else {
                        if(课程状态 ==='开始') {
                            alert("报名成功!欢迎进入课程");
                        } else {
                            alert("报名成功!直播入口将在开课前10分钟打开");
                        }
                    }
                    window.location.href="<?=$yuyin?>";
                }else {
                    alert("报名失败!");
                }
            });
        } else {
            alert('同一时间内您已报名其他课程');
        }

    }

    function f修改课程状态(状态){
        $.post('agent_manages.php',{'课程id':'<?= $课程id?>',"状态":状态,'参数':'修改课程状态'},function(data){

            if(data){
                alert(状态+"课程成功!");
                location.replace(location.href);
            }else {
                alert(状态+"课程失败!");
            }
        });
    }
    function f人数(){
        alert("本课程报名人数已达上限，请持续关注爱贝儿医，更多精彩课程会陆续更新，谢谢！");
    }
    function f直播(){
        alert("该课程正在直播，您未报名暂时不能进入课程，请课程结束后观看课程回放，谢谢您的支持与厚爱！");
    }

    wx.config({
        debug: false,
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp: <?php echo $signPackage["timestamp"];?>,
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: [
            'onMenuShareAppMessage',
            'onMenuShareTimeline',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone'
        ]
    });

    <?php
        $desc = mb_substr(strip_tags($语音课程['详情']), 0, 100, 'utf-8');
        $desc = str_replace('&nbsp', ' ', $desc);
        $avatar = trim($语音课程['头像']);
        if (!$avatar) {
            $avatar = G_SITE_BASE .'/business/img/default_avatar.jpg';
        }
        if (substr($avatar, 0, 4) != 'http') {
            $avatar = G_SITE_BASE .'/business/'. $avatar;
        }
    ?>

    title = '<?= $语音课程['title']?>';
    desc = '【欢迎报名】<?= $desc?>';
    links = '';
    imgUrl = '<?= $avatar?>';
    weixinShare(title, desc, links, imgUrl);

</script>